<?xml version="1.0" encoding="UTF-8" standalone="no"?><HBRRepo><variables/><rulesets/><rules><rule id="1" name="OFS_Trend Based Calculation" product="Planning"><property name="application">HP4</property><property name="plantype">OEP_FS</property><property name="display_label">OFS_Trend Based Calculation</property><property name="enableNotifications">false</property><property name="enablePostProcessing">false</property><property name="enablePreProcessing">false</property><property name="seeded">true</property><script type="groovy"><![CDATA[        DataGrid grid = null;
	    String planElementDimName = "Plan Element"
        String flexDim1Name = "Market"
		String flexDim2Name = "RevenueDriver2"
		String flexDim3Name = "RevenueDriver3"
		String productDimName  = "Product"
		String serviceDimName  = "RevenueSource2"
		String entityDimName = "Entity"
        Cube financialsCube = operation.cube
		def weeklyCondition
		boolean is13PeriodApp = TemporaryInternalMethods.is13PeriodApp()
		weeklyCondition = is13PeriodApp ? '(@ismbr(@remove(@relative("OEP_Weekly Plan", 0),"OEP_W53"))) or ("TP-Weeks" == 53 and @ismbr(@relative("OEP_Weekly Plan", 0)))' : '@ismbr(@relative("OEP_Weekly Plan", 0))'
		try {
        	grid = operation.grid;
        } catch(BindingsMissingException) {
        	return  '''OFS_Calculated (
          			@RETURN(@HspMessage("ID_Err_FINANCIALS_TREND_BASED_TO_BE_RUN_FROM_FORM"),ERROR);
                   )'''
        }
        //Check if the trend is revision trend or not
        Map<Long, Set<String>> trendsAndAccountsMap = [:]
        grid.dataCellIterator({ DataCell cell -> !cell.missing && cell.getMemberName(planElementDimName) == "OFS_Trend" && cell.periodName == "BegBalance"}).each { dataCell ->
        	long trend = (long) dataCell.data
        	Set<String> accounts = trendsAndAccountsMap.get(trend)
            if(!accounts) {
            	accounts = new HashSet<String>()
            	trendsAndAccountsMap.put(trend, accounts)
            }
			accounts.add(dataCell.accountName)
		}
        %Template(name:="OFS_GridMemberSelection_GT",plantype:="OEP_FS",dtps:=())
		GridMemberSelection gridMemberSelection = new GridMemberSelection(grid)
        Set<Long> capturedTrends = trendsAndAccountsMap.keySet()
		long CURRENT_PERIOD_ACTUAL_TREND = 2l
		long CLEAR_TREND = 12l
		long CURRENT_YEAR_ENCUMBRANCE_TREND = 51l
		long NET_CURRENT_BUDGET_TREND = 56l
		long CURRENT_YEAR_APPROVED_BUDGET_TREND = 61l
		long CURRENT_YEAR_ORIGINAL_BUDGET_TREND = 66l
        Set<Long> exclusiveRevisionTrends = [CURRENT_YEAR_ENCUMBRANCE_TREND, CURRENT_YEAR_APPROVED_BUDGET_TREND, CURRENT_YEAR_ORIGINAL_BUDGET_TREND, NET_CURRENT_BUDGET_TREND] as HashSet
		Set<Long> revisionTrendsWithOutClearTrend = exclusiveRevisionTrends + [CURRENT_PERIOD_ACTUAL_TREND]
        Set<Long> revisionTrends = revisionTrendsWithOutClearTrend + [CLEAR_TREND]
        def versionDimension = operation.application.getDimension(DimensionType.VERSION, financialsCube)
        def netCurrentBudgetRevisions = versionDimension.hasMember("OEP_Net Current Budget", financialsCube) ? (versionDimension.getEvaluatedMembers(/ILvl0Descendants("OEP_Net Current Budget")/, financialsCube).collect{it.toString()}) : []
        def budgetRevisionVersions = netCurrentBudgetRevisions - "[OEP_Net Current Budget].[OEP_Working]"
        def versions = gridMemberSelection.getMemberSelection("Version")
		boolean isBudgetRevision
		if( budgetRevisionVersions.containsAll(versions) ) {
			isBudgetRevision = true
		} else if( budgetRevisionVersions.intersect(versions) ) {
			throwVetoException(new HspRuntimeException("ERR_BUDGET_REVISIONS_TREND_CALC_REVISION_AND_NONREVISION"))
		}
        
		//FIXME: What to do when no accounts,trend, Adjustment percentage are modified. Need to identify the Version is a Revision version or not
        if(isBudgetRevision) {
			if( versions.size() > 1) {
				throwVetoException(new HspRuntimeException("ERR_BUDGET_REVISION_TREND_CALC_MULTIPLE_REVISIONS"))
			}
			String version = versions.get(0)
        	if(!revisionTrends.containsAll(capturedTrends)) {
            	throwVetoException("You can't use the trend you selected in a budget revision. Valid trends are ${revisionTrends.collect{operation.application.getSmartList("OFS_Trend").getEntry(it).getLabel()}}.")
            }
            def periodSelectionForDataCopy = 'ILvl0Descendants("YearTotal"),ILvl0Descendants("OEP_Qrtly Plan"),ILvl0Descendants("OEP_Yearly Plan")'
            def yearsSelection = gridMemberSelection.getMemberSelection("Years")
            def entitySelection = gridMemberSelection.getMemberSelection(entityDimName)
            def currencySelection
            if(operation.application.getCurrencyMode().equals(CurrencyMode.SIMPLIFIED_MULTI_CURRENCY)){
            	currencySelection = gridMemberSelection.getMemberSelection("Currency")
            }
            def flexDim1Selection
            if(operation.application.hasDimension(flexDim1Name, financialsCube)){
            	flexDim1Selection = gridMemberSelection.getMemberSelection(flexDim1Name)
            }
            def flexDim2Selection
            if(operation.application.hasDimension(flexDim2Name, financialsCube)){
            	flexDim2Selection = gridMemberSelection.getMemberSelection(flexDim2Name)
            }
            def flexDim3Selection
            if(operation.application.hasDimension(flexDim3Name, financialsCube)){
            	flexDim3Selection = gridMemberSelection.getMemberSelection(flexDim3Name)
            }
            def productDimSelection
            if(operation.application.hasDimension(productDimName, financialsCube)){
            	productDimSelection = gridMemberSelection.getMemberSelection(productDimName)
            }
            def serviceDimSelection
            if(operation.application.hasDimension(serviceDimName, financialsCube)){
            	serviceDimSelection = gridMemberSelection.getMemberSelection(serviceDimName)
            }
			List<String> fixMembers = []
			fixMembers.addAll(yearsSelection)
            fixMembers.addAll(entitySelection)
			if(currencySelection) {
				fixMembers.addAll(currencySelection)
			}
			if(flexDim1Selection) {
				fixMembers.addAll(flexDim1Selection)
			}
			if(flexDim2Selection) {
				fixMembers.addAll(flexDim2Selection)
			}
			if(flexDim3Selection) {
				fixMembers.addAll(flexDim3Selection)
			}
			if(productDimSelection) {
				fixMembers.addAll(productDimSelection)
			}
			if(serviceDimSelection) {
				fixMembers.addAll(serviceDimSelection)
			}
        	capturedTrends.each { trendSmartListEntryId ->
                def dimToDimMapping = ["Period":(trendSmartListEntryId == CURRENT_PERIOD_ACTUAL_TREND? "&OEP_CurMnth" : periodSelectionForDataCopy), "Years":yearsSelection.collect{/"$it"/}.join(','), (entityDimName):entitySelection.collect{/"$it"/}.join(',')]
                if(currencySelection) {
                	dimToDimMapping.put("Currency", currencySelection.collect{/"$it"/}.join(','))
                }
                if(flexDim1Selection) {
                	dimToDimMapping.put(flexDim1Name, flexDim1Selection.collect{/"$it"/}.join(','))
                }
                if(flexDim2Selection) {
                	dimToDimMapping.put(flexDim2Name, flexDim2Selection.collect{/"$it"/}.join(','))
                }
                if(flexDim3Selection) {
                	dimToDimMapping.put(flexDim3Name, flexDim3Selection.collect{/"$it"/}.join(','))
                }
                if(productDimSelection) {
                	dimToDimMapping.put(productDimName, productDimSelection.collect{/"$it"/}.join(','))
                }
                if(serviceDimSelection) {
                	dimToDimMapping.put(serviceDimName, serviceDimSelection.collect{/"$it"/}.join(','))
                }
            	def accountMembers = trendsAndAccountsMap.get(trendSmartListEntryId)
                dimToDimMapping.put("Account", accountMembers.collect{/"$it"/}.join(','))
                String sourceScenarioSelectionForDataCopy, targetScenarioSelectionForDataCopy, sourceVersionSelectionForDataCopy, sourcePlanElementSelectionForDataCopy, targetPlanElementSelectionForDataCopy
                if(trendSmartListEntryId == CURRENT_YEAR_ENCUMBRANCE_TREND) {
                    sourceScenarioSelectionForDataCopy = 'OEP_Consumed'
                    targetScenarioSelectionForDataCopy = 'OEP_Adopted Budget'
                    sourceVersionSelectionForDataCopy = 'OEP_Working'
                    sourcePlanElementSelectionForDataCopy = 'ILvl0Descendants("OFS_Total Plan")'
                    targetPlanElementSelectionForDataCopy = 'OFS_Calculated'
                } else if(trendSmartListEntryId == CURRENT_PERIOD_ACTUAL_TREND) {
                    sourceScenarioSelectionForDataCopy = 'OEP_Actual'
                    targetScenarioSelectionForDataCopy = 'OEP_Adopted Budget'
                    sourceVersionSelectionForDataCopy = 'OEP_Working'
                    sourcePlanElementSelectionForDataCopy = 'ILvl0Descendants("OFS_Total Plan")'
                    targetPlanElementSelectionForDataCopy = 'OFS_Calculated'
                } else if(trendSmartListEntryId == CURRENT_YEAR_APPROVED_BUDGET_TREND) {
                    sourceScenarioSelectionForDataCopy = 'OEP_Adopted Budget'
                    targetScenarioSelectionForDataCopy = 'OEP_Adopted Budget'
                    sourceVersionSelectionForDataCopy = 'OEP_Working'
                    sourcePlanElementSelectionForDataCopy = 'ILvl0Descendants("OFS_Total Plan")'
                    targetPlanElementSelectionForDataCopy = 'OFS_Calculated'
                } else if(trendSmartListEntryId == CURRENT_YEAR_ORIGINAL_BUDGET_TREND) {
                    sourceScenarioSelectionForDataCopy = 'OEP_Adopted Budget'
                    targetScenarioSelectionForDataCopy = 'OEP_Adopted Budget'
                    sourceVersionSelectionForDataCopy = 'OEP_Original'
                    sourcePlanElementSelectionForDataCopy = 'ILvl0Descendants("OFS_Total Plan")'
                    targetPlanElementSelectionForDataCopy = 'OFS_Calculated'
                } else if(trendSmartListEntryId == NET_CURRENT_BUDGET_TREND) {
                    sourceScenarioSelectionForDataCopy = 'OEP_Adopted Budget'
                    targetScenarioSelectionForDataCopy = 'OEP_Adopted Budget'
                    //sourceVersionSelectionForDataCopy = 'ILvl0Descendants("OEP_Net Current Budget")'
                    sourceVersionSelectionForDataCopy = (netCurrentBudgetRevisions - version).collect{/"$it"/}.join(',')
                    sourcePlanElementSelectionForDataCopy = 'ILvl0Descendants("OFS_Total Plan")'
                    targetPlanElementSelectionForDataCopy = 'OFS_Calculated'
                } else if(trendSmartListEntryId == CLEAR_TREND) {
                    //Valid trend
                } else {
                    //FIXME: Remove this after handling all trends
                    throwVetoException("You can't select the trend: " + operation.application.getSmartList("OFS_Trend").getEntry(trendSmartListEntryId).getLabel())
                }
				
				if(trendSmartListEntryId != CLEAR_TREND) {
					Map<String,String> unmappedSource = ["Scenario":sourceScenarioSelectionForDataCopy, "Version":sourceVersionSelectionForDataCopy, (planElementDimName):sourcePlanElementSelectionForDataCopy]
					Map<String,String> unmappedTarget = ["Scenario":targetScenarioSelectionForDataCopy, "Version":version, (planElementDimName):targetPlanElementSelectionForDataCopy]
					TemporaryInternalMethods.copyAndAggregateDataOfBudgetRevision("OnTheFlyDataMap", financialsCube, dimToDimMapping, unmappedSource, unmappedTarget, true)
				}
            }
			if(capturedTrends) {
				def revisionCalc = ''
				if(trendsAndAccountsMap.containsKey(CLEAR_TREND)) {
					revisionCalc += """
						FIX(${fixMembers.collect{/"$it"/}.join(',')},${trendsAndAccountsMap.get(CLEAR_TREND).collect{/"$it"/}.join(',')},"OEP_Adopted Budget")
                        	FIX("OFS_Calculated", @Relative("YearTotal",0), @relative("OEP_Qrtly Plan",0), @relative("OEP_Yearly Plan",0))
								$version = #missing;
                            ENDFIX;
                            FIX("OFS_% Increase/(Decrease)", "BegBalance")
                            	$version = #missing;
                            ENDFIX;
						ENDFIX;"""
				}
				
				if(trendsAndAccountsMap.keySet().intersect(revisionTrendsWithOutClearTrend as HashSet)) {
                    revisionCalc += """
                    				FIX(${fixMembers.collect{/"$it"/}.join(',')},"OEP_Adopted Budget", "OFS_Calculated")"""
					if(trendsAndAccountsMap.keySet() - [CURRENT_PERIOD_ACTUAL_TREND, CLEAR_TREND]) {
						revisionCalc += """
							FIX(@Relative("YearTotal",0), @relative("OEP_Qrtly Plan",0), @relative("OEP_Yearly Plan",0), ${trendsAndAccountsMap.entrySet().collect{it.key!=CLEAR_TREND && it.key!=CURRENT_PERIOD_ACTUAL_TREND?it.value:[]}.flatten().collect{/"$it"/}.join(',')})
								$version = $version * "OFS_% Increase/(Decrease)"->"BegBalance";
							ENDFIX;"""
					}
					
					if(trendsAndAccountsMap.containsKey(CURRENT_PERIOD_ACTUAL_TREND)) {
						revisionCalc += """
						FIX(@Relative("YearTotal",0), ${trendsAndAccountsMap.get(CURRENT_PERIOD_ACTUAL_TREND).collect{/"$it"/}.join(',')})
							$version = $version -> &OEP_CurMnth * "OFS_% Increase/(Decrease)"->"BegBalance";
						ENDFIX;"""
					}
                    revisionCalc += """
                    				ENDFIX;"""
				}
				
				revisionCalc += """
						FIX(${fixMembers.collect{/"$it"/}.join(',')},$version,"OEP_Adopted Budget", "OFS_Calculated", @Relative("YearTotal",0), @relative("OEP_Qrtly Plan",0), @relative("OEP_Yearly Plan",0))
							CALC DIM("Account");
						ENDFIX;"""
				financialsCube.executeCalcScript(revisionCalc)
			}
        	
        } else {
			if(capturedTrends.intersect(exclusiveRevisionTrends)) {
            	throwVetoException("You can't use the trend you selected. You can use ${exclusiveRevisionTrends.collect{operation.application.getSmartList("OFS_Trend").getEntry(it).getLabel()}} trends only in budget revision versions.")
			}
        	boolean processAccount = false;
			StringBuilder cscript = new StringBuilder(); // The variable that contains the actual script that will be returned at the end.
			List<DataGrid.HeaderCell> povs = grid.getPov();
			List<String> fixMembers = new ArrayList<String>();
			Set<String> accts = new HashSet<String>();
			List<String> periods = new ArrayList<String>();
			for (DataGrid.HeaderCell cell : povs) {
				if (cell.isCalcableForPOV()) {
					if ((!(cell.isZoomable())) && !cell.getDimName().equals(planElementDimName) ) {
						fixMembers.add(cell.getEssbaseMbrName());
					} else if (cell.getDimName().equalsIgnoreCase("Account")) {
						 String memName = cell.getEssbaseMbrName();
						 if(memName == null)
							  memName = cell.getMbrName();
						 accts.add(memName);
						processAccount = true;
					}else if (cell.getDimName().equalsIgnoreCase("Period") ) {
							if(cell.isCalcableForPOV()){
							   String memName = cell.getEssbaseMbrName();
							   if(memName == null)
									memName = cell.getMbrName();
							   if(!periods.contains(memName))
								periods.add(memName);
						   }
					}
				}
			}

			List<DataGrid.Row> rows = grid.getRows();

			//Since need to fix on Periods, removing the processAccount check. If Accounts are already processed, it will not come here anyways.
				for (DataGrid.Row row : rows) {
					List<DataGrid.HeaderCell> subRows = row.getHeaders();
					for (DataGrid.HeaderCell cell : subRows) {
						if (cell.getDimName().equalsIgnoreCase("Account")) {
						  String memName = cell.getEssbaseMbrName();
						  if(memName == null)
							  memName = cell.getMbrName();
						   accts.add(memName);
							processAccount = true;
						}else if (cell.getDimName().equalsIgnoreCase("Period") ) {
							if(cell.isCalcableForPOV()){
							   String memName = cell.getEssbaseMbrName();
							   if(memName == null)
									memName = cell.getMbrName();
							   if(!periods.contains(memName))
								periods.add(memName);
						   }
						} 
					}
				}


			
				List<List<DataGrid.HeaderCell>> cols = grid.getColumns();
				for (List<DataGrid.HeaderCell> cells : cols) {
					for (DataGrid.HeaderCell cell : cells) {
						if (cell.getDimName().equalsIgnoreCase("Account")) {
						  String memName = cell.getEssbaseMbrName();
						  if(memName == null)
							  memName = cell.getMbrName();
						   accts.add(memName);
							processAccount = true;
						}else if (cell.getDimName().equalsIgnoreCase("Period") ) {
							if(cell.isCalcableForPOV()){
							   String memName = cell.getEssbaseMbrName();
							   if(memName == null)
									memName = cell.getMbrName();
							   if(!periods.contains(memName))
								periods.add(memName);
						   }
						} else {
							break;
						}
					}
				}
			

			int indx = 0;
			for (String fixMbr : fixMembers) {
				if (indx == 0) {

					cscript.append('''FIX( ''');
				}

				 cscript.append("\"" + fixMbr + "\"");
				if (indx < (fixMembers.size() - 1))
					 cscript.append(",");
				indx++;
			}

			for (String fixMbr : periods) {
			   if(indx > 0 ){
				  cscript.append(",");
				  cscript.append("\"" + fixMbr + "\"");
				}
			}
			

			if (fixMembers.size() > 0)
				 cscript.append(")\n");

			if (accts.size() > 0)
				processAccount = true;

			indx = 0;

			for (String acct : accts) {
				if (indx == 0) {
					String msg = "";
					
					 cscript.append('''FIX(''');

				}

				 cscript.append("\"" + acct + "\"");
				if (indx < (accts.size() - 1))
					cscript.append(",");
				indx++;
			}

			if (processAccount) {
				 cscript.append(") \n");
				 
				  cscript.append("\"OFS_Calculated\" ( \n")
				if(operation.application.currencyMode == CurrencyMode.SIMPLIFIED_MULTI_CURRENCY) {
					 cscript.append("if(@ismbr(@relative(\"Input Currencies\",0))) \n ")
				}

				 def trendLogic = '''
			 if(@ismbr("OEP_Forecast"))	

			 '''  ;
			 
			 def weeklyScript = """
		if($weeklyCondition)    
			If(@sumrange(&OEP_CurYr->OEP_Actual->OFS_Load,OEP_W1:&OEP_CurWeek)<>#missing) 					   	
				If(Not(@ismbr(&OEP_CurYr) and @ismbr(OEP_W1:&OEP_CurWeek))) 
					%Script(name:="Weekly_Trends")									
					%Script(name:="Weekly_ForecastOnly")											
					endif         
				endif 
			endif
		else
			if(@ismbr(@relative("YearTotal",0)))			
				If(Not(@ismbr(&OEP_CurYr) and @ismbr(&OEP_StartMnth:&OEP_CurMnth)))		
					%Script(name:="Monthly_Trends")	
					%Script(name:="Forecast_Only_Trends")	
					endif 	
				endif		
			
			elseif(@ismbr(@relative("OEP_Qrtly Plan",0)))
				if(@ismbr(&OEP_QrtlyFcstStart:&OEP_QrtlyFcstEnd))	
						%Script(name:="Qrtly_Trends")											
				endif
			
			elseif(@ismbr("OEP_Yearly Plan"))
				if(@ismbr(&OEP_YrlyFcstStart:&OEP_YrlyFcstEnd))																											
					%Script(name:="Yearly_Trends")											
				endif													
			endif
		 endif   
	elseif(@ismbr("OEP_Plan"))	
			if(@ismbr(@relative("OEP_Weekly Plan",0)))
				  %Script(name:="Weekly_Trends")	
				   %Script(name:="Plan_Only_Weekly")	
				  endif
			
			elseif(@ismbr(@relative("YearTotal",0)))																											
					%Script(name:="Monthly_Trends")											
					%Script(name:="Plan_Only_Trends")											
				endif
			
			elseif(@ismbr(@relative("OEP_Qrtly Plan",0)))
				if(@ismbr(&OEP_QrtlyPlanStart:&OEP_QrtlyPlanEnd))																											
				%Script(name:="Qrtly_Trends")											
				endif												
			elseif(@ismbr("OEP_Yearly Plan"))	
				if(@ismbr(&OEP_YrlyPlanStart:&OEP_YrlyPlanEnd))													    													
				%Script(name:="Yearly_Trends")											
				endif												
		endif			     
												
	endif """

		def nonWeeklyScript = '''
		if(@ismbr(@relative("YearTotal",0)))			
				If(Not(@ismbr(&OEP_CurYr) and @ismbr(&OEP_StartMnth:&OEP_CurMnth)))		
					%Script(name:="Monthly_Trends")	
					%Script(name:="Forecast_Only_Trends")	
					endif 	
				endif    
		
		elseif(@ismbr(@relative("OEP_Qrtly Plan",0)))
			if(@ismbr(&OEP_QrtlyFcstStart:&OEP_QrtlyFcstEnd))																											
				%Script(name:="Qrtly_Trends")
			endif												
															
		elseif(@ismbr("OEP_Yearly Plan"))
				if(@ismbr(&OEP_YrlyFcstStart:&OEP_YrlyFcstEnd))																											
				%Script(name:="Yearly_Trends")											
			endif												
		endif	
	elseif(@ismbr("OEP_Plan"))	
		if(@ismbr(@relative("YearTotal",0)))
		if(@ismbr(&OEP_PlanStartYr:&OEP_PlanEndYr))													
				%Script(name:="Monthly_Trends")											
				%Script(name:="Plan_Only_Trends")											
				endif 											
				endif		

		  elseif(@ismbr(@relative("OEP_Qrtly Plan",0)))
				if(@ismbr(&OEP_QrtlyPlanStart:&OEP_QrtlyPlanEnd))																											
				%Script(name:="Qrtly_Trends")											
				endif												
			elseif(@ismbr("OEP_Yearly Plan"))
			 if(@ismbr(&OEP_YrlyPlanStart:&OEP_YrlyPlanEnd))													    														
				%Script(name:="Yearly_Trends")											
				endif												
		endif			     
												
	endif  '''
		boolean weeklyPlanExists = operation.application.getDimension(DimensionType.PERIOD, operation.cube).hasMember("OEP_Weekly Plan", operation.cube);
		if(weeklyPlanExists){
			trendLogic = trendLogic << weeklyScript;
		}else{
			trendLogic = trendLogic << nonWeeklyScript;
		}


	 cscript.append(trendLogic);

				if(operation.application.currencyMode == CurrencyMode.SIMPLIFIED_MULTI_CURRENCY) {
					cscript.append("\nENDIF \n");
				}
				 
				cscript.append(") \n");

				cscript.append("\nENDFIX \n");
			}

			String msg = "ENDFIX \n";
			cscript.append(msg);
			return cscript.toString();

        }
        
]]></script></rule></rules><components><component id="4" name="Forecast_Only_Trends" product="Planning" type="script"><property name="application">HP4</property><property name="plantype">OEP_FS</property><property name="display_label">Forecast_Only_Trends</property><property name="seeded">true</property><script type="calcscript"><![CDATA[elseif("OFS_Trend"->"BegBalance"==10)
				if(@isuda("Account","calcRound"))
                	IF(@ISMBR(&OEP_CurYr))
						"OFS_Calculated" = @Round(@prior("Actual"->"OFS_Total Plan"->"YearTotal",1,@LEVMBRS ("Years", 0))/12*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
                    ELSE
                    	"OFS_Calculated" = @Round(@prior("OFS_Total Plan"->"YearTotal",1,@LEVMBRS ("Years", 0))/12*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
                    ENDIF    
				else
                	IF(@ISMBR(&OEP_CurYr))
						"OFS_Calculated" = @prior("Actual"->"OFS_Total Plan"->"YearTotal",1,@LEVMBRS ("Years", 0))/12*(1+"OFS_% Increase/(Decrease)"->"BegBalance");
                    ELSE
                    	"OFS_Calculated" = @prior("OFS_Total Plan"->"YearTotal",1,@LEVMBRS ("Years", 0))/12*(1+"OFS_% Increase/(Decrease)"->"BegBalance");
                    ENDIF    
				endif
elseif("OFS_Trend"->"BegBalance"==3)
			if(@sumrange("OEP_Plan"->"OFS_Total Plan",&OEP_StartMnth:&OEP_EndMnth)-@sumrange("OEP_Actual"->"OFS_Load",&OEP_StartMnth:&OEP_CurMnth)>0)
				if(@ISACCTYPE(LAST))
					if(@isuda("Account","Calcround"))
						"OFS_Calculated"=@round("OEP_Plan"->"OFS_Total Plan");
					else
						"OFS_Calculated" ="OEP_Plan"->"OFS_Total Plan";
					endif
				else
					if(@isuda("Account","Calcround"))
						"OFS_Calculated"=@round(((@sumrange("OEP_Plan"->"OFS_Total Plan",&OEP_StartMnth:&OEP_EndMnth))-(@sumrange("OEP_Actual"->"OFS_Load",&OEP_StartMnth:&OEP_CurMnth)))/@count(skipnone,&OEP_FcstMnth:&OEP_EndMnth));
					else
						"OFS_Calculated"=((@sumrange("OEP_Plan"->"OFS_Total Plan",&OEP_StartMnth:&OEP_EndMnth))-(@sumrange("OEP_Actual"->"OFS_Load",&OEP_StartMnth:&OEP_CurMnth)))/@count(skipnone,&OEP_FcstMnth:&OEP_EndMnth);
					endif
				endif
			else
				"OFS_Calculated"=#missing;
			endif
    @calcmode(cell);
		elseif("OFS_Trend"->"BegBalance"==35)			
			if(@ismbr(&OEP_FCSTStartYr))
				if(@ismbr(&OEP_FcstMnth))
					if(@ismbr(@MBRCOMPARE("==", &OEP_FcstMnth, &OEP_StartMnth)))
						if(@isuda("Account","calcRound"))
							OFS_Calculated=@round((@prior("OFS_Load"->OEP_Actual->&OEP_EndMnth,1,@levmbrs(Years,0))*(@prior("OFS_Load"->OEP_Actual,1,@LEVMBRS ("Years", 0))+@prior("OFS_Load"->OEP_Actual,2,@LEVMBRS ("Years", 0)))/					
							(@prior( "OFS_Load"->OEP_Actual->&OEP_EndMnth, 2,@levmbrs(Years,0) )+@prior( "OFS_Load"->OEP_Actual->&OEP_EndMnth, 3,@levmbrs(Years,0) )))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
						else
							OFS_Calculated=((@prior("OFS_Load"->OEP_Actual->&OEP_EndMnth,1,@levmbrs(Years,0))*(@prior("OFS_Load"->OEP_Actual,1,@LEVMBRS ("Years", 0))+@prior("OFS_Load"->OEP_Actual,2,@LEVMBRS ("Years", 0)))/
  							(@prior( "OFS_Load"->OEP_Actual->&OEP_EndMnth, 2,@levmbrs(Years,0) )+@prior( "OFS_Load"->OEP_Actual->&OEP_EndMnth, 3,@levmbrs(Years,0) )))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
						endif
					else
						if(@isuda("Account","calcRound"))
							OFS_Calculated=@round((@prior("OFS_Load"->OEP_Actual->&OEP_CurYr)*(@prior("OFS_Load"->OEP_Actual,1,@LEVMBRS ("Years", 0))+@prior("OFS_Load"->OEP_Actual,2,@LEVMBRS ("Years", 0)))/					
							(@MDSHIFT( "OFS_Load"->OEP_Actual, -1, "Period",@relative(YearTotal,0) , -1, "Years", )+@MDSHIFT( "OFS_Load"->OEP_Actual, -1, "Period",@relative(YearTotal,0) , -2, "Years", )))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
						else
							OFS_Calculated=((@prior("OFS_Load"->OEP_Actual->&OEP_CurYr)*(@prior("OFS_Load"->OEP_Actual,1,@LEVMBRS ("Years", 0))+@prior("OFS_Load"->OEP_Actual,2,@LEVMBRS ("Years", 0)))/					
							(@MDSHIFT( "OFS_Load"->OEP_Actual, -1, "Period",@relative(YearTotal,0) , -1, "Years", )+@MDSHIFT( "OFS_Load"->OEP_Actual, -1, "Period",@relative(YearTotal,0) , -2, "Years", )))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
						endif
					endif
				else
					if(@isuda("Account","calcRound"))
						OFS_Calculated=@round((@prior("OFS_Calculated")*(@prior("OFS_Load"->OEP_Actual,1,@LEVMBRS ("Years", 0))+@prior("OFS_Load"->OEP_Actual,2,@LEVMBRS ("Years", 0)))/
                        (@MDSHIFT( "OFS_Load"->OEP_Actual, -1, "Period",@relative(YearTotal,0) , -1, "Years", )+@MDSHIFT( "OFS_Load"->OEP_Actual, -1, "Period",@relative(YearTotal,0) , -2, "Years", )))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
					else
						OFS_Calculated=((@prior("OFS_Calculated")*(@prior("OFS_Load"->OEP_Actual,1,@LEVMBRS ("Years", 0))+@prior("OFS_Load"->OEP_Actual,2,@LEVMBRS ("Years", 0)))/
                        (@MDSHIFT( "OFS_Load"->OEP_Actual, -1, "Period",@relative(YearTotal,0) , -1, "Years", )+@MDSHIFT( "OFS_Load"->OEP_Actual, -1, "Period",@relative(YearTotal,0) , -2, "Years", )))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
					endif
				endif
			elseif(@ismbr(@RSIBLINGS(&OEP_FCSTStartYr)))
				if(@ismbr(&OEP_StartMnth))
					if(@isuda("Account","calcRound"))
						OFS_Calculated=@round((@prior("OFS_Calculated"->&OEP_EndMnth,1,@levmbrs(Years,0))*(@prior("OFS_Calculated",1,@LEVMBRS ("Years", 0))+@prior("OFS_Load"->OEP_Actual,2,@LEVMBRS ("Years", 0)))/					
						(@prior( "OFS_Load"->OEP_Actual->&OEP_EndMnth, 2,@levmbrs(Years,0) )+@prior( "OFS_Load"->OEP_Actual->&OEP_EndMnth, 3,@levmbrs(Years,0))))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
					else
						OFS_Calculated=((@prior("OFS_Calculated"->&OEP_EndMnth,1,@levmbrs(Years,0))*(@prior("OFS_Calculated",1,@LEVMBRS ("Years", 0))+@prior("OFS_Load"->OEP_Actual,2,@LEVMBRS ("Years", 0)))/
                        (@prior( "OFS_Load"->OEP_Actual->&OEP_EndMnth, 2,@levmbrs(Years,0) )+@prior( "OFS_Load"->OEP_Actual->&OEP_EndMnth, 3,@levmbrs(Years,0))))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
					endif
				else
					if(@isuda("Account","calcRound"))
						OFS_Calculated=@round((@prior("OFS_Calculated")*(@prior("OFS_Calculated",1,@LEVMBRS ("Years", 0))+@prior("OFS_Load"->OEP_Actual,2,@LEVMBRS ("Years", 0)))/					
						(@MDSHIFT( "OFS_Calculated", -1, "Period",@relative(YearTotal,0) , -1, "Years", )+@MDSHIFT( "OFS_Load"->OEP_Actual, -1, "Period",@relative(YearTotal,0) , -2, "Years", )))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
					else
						OFS_Calculated=((@prior("OFS_Calculated")*(@prior("OFS_Calculated",1,@LEVMBRS ("Years", 0))+@prior("OFS_Load"->OEP_Actual,2,@LEVMBRS ("Years", 0)))/
                        (@MDSHIFT( "OFS_Calculated", -1, "Period",@relative(YearTotal,0) , -1, "Years", )+@MDSHIFT( "OFS_Load"->OEP_Actual, -1, "Period",@relative(YearTotal,0) , -2, "Years", )))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
					endif
				endif
			endif
	@calcmode(block);
		elseif("OFS_Trend"->"BegBalance"==36)			
			if(@isuda("Account","calcRound"))					
		if(@ismbr(&OEP_FcstMnth) and @ismbr(&OEP_FcstStartYr))	
			"OFS_Calculated"=@round((@prior("OFS_Load"->OEP_Actual->&OEP_CurYr))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));			
		elseif(@ismbr(&OEP_StartMnth) and @ismbr(@RSIBLINGS(&OEP_FCSTStartYr)))
       		"OFS_Calculated"=@round((@Prior("OFS_Total Plan"->&OEP_EndMnth,1,@LEVMBRS ("Years", 0)))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
				else			
			"OFS_Calculated" =@round((@prior("OFS_Calculated")+@prior("OFS_Adjustment (+/-)"))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));			
				endif	
			else		
		if(@ismbr(&OEP_FcstMnth) and @ismbr(&OEP_FcstStartYr))	
			"OFS_Calculated"=@prior("OFS_Load"->OEP_Actual->&OEP_CurYr)*(1+"OFS_% Increase/(Decrease)"->"BegBalance");			
		elseif(@ismbr(&OEP_StartMnth) and @ismbr(@RSIBLINGS(&OEP_FCSTStartYr)))
        	"OFS_Calculated"=@Prior("OFS_Total Plan"->&OEP_EndMnth,1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");
				else
			"OFS_Calculated" =(@prior("OFS_Calculated")+@prior("OFS_Adjustment (+/-)"))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");			
				endif	
			endif]]></script></component><component id="3" name="Monthly_Trends" product="Planning" type="script"><property name="application">HP4</property><property name="plantype">OEP_FS</property><property name="display_label">Monthly_Trends</property><property name="seeded">true</property><script type="calcscript"><![CDATA[If("OFS_Trend"->"BegBalance"==1)						
	if(@isuda("Account","CalcRound"))					
		OFS_Calculated = @Round(@AVGRANGE(SKIPNONE , "OEP_Actual"->"OFS_Load"->&OEP_CurYr , &OEP_StartMnth:&OEP_CurMnth)*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));				
	else					
		OFS_Calculated =@AVGRANGE(SKIPNONE , "OEP_Actual"->"OFS_Load"->&OEP_CurYr , &OEP_StartMnth:&OEP_CurMnth)*(1+"OFS_% Increase/(Decrease)"->"BegBalance");				
	endif					
elseif("OFS_Trend"->"BegBalance"==2)						
	if(@isuda("Account","CalcRound"))					
		OFS_Calculated =@Round(("OEP_Actual"->&OEP_CurMnth->&OEP_CurYr->"OFS_Load")*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));				
	else					
		OFS_Calculated = ("OEP_Actual"->&OEP_CurMnth->&OEP_CurYr->"OFS_Load")*(1+"OFS_% Increase/(Decrease)"->"BegBalance");				
	endif					
						
elseif("OFS_Trend"->"BegBalance"==4)						
	if(@isuda("Account","CalcRound"))					
		OFS_Calculated = @Round(@avgrange(skipnone,"OEP_Actual"->"OFS_Load"->&OEP_PriorYr,@relative("YearTotal",0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));				
	else					
		OFS_Calculated = @avgrange(skipnone,"OEP_Actual"->"OFS_Load"->&OEP_PriorYr,@relative("YearTotal",0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");				
	endif					
elseif("OFS_Trend"->"BegBalance"==5)						
	if(@isuda("Account","CalcRound"))					
		OFS_Calculated = @Round(("OEP_Actual"->"OFS_Load"->&OEP_PriorYr)*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));				
	else					
		OFS_Calculated = ("OEP_Actual"->"OFS_Load"->&OEP_PriorYr)*(1+"OFS_% Increase/(Decrease)"->"BegBalance");				
	endif					
elseif("OFS_Trend"->BegBalance==12)						
	OFS_Calculated =#missing;					
elseif("OFS_Trend"->BegBalance==#missing and "OFS_Adjustment (+/-)"<>#missing)										
	OFS_Calculated=0;
    OFS_Calculated=#missing;					
					
]]></script></component><component id="8" name="Plan_Only_Trends" product="Planning" type="script"><property name="application">HP4</property><property name="plantype">OEP_FS</property><property name="display_label">Plan_Only_Trends</property><property name="seeded">true</property><script type="calcscript"><![CDATA[elseif("OFS_Trend"->"BegBalance"==6)
			if(@isuda("Account","CalcRound"))
				"OFS_Calculated" = @Round(@avgrange(skipnone,"OEP_Forecast"->"OFS_Total Plan"->@member(@prevsibling(@currmbr(Years))),@relative("YearTotal",0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
			else
				"OFS_Calculated" = @avgrange(skipnone,"OEP_Forecast"->"OFS_Total Plan"->@member(@prevsibling(@currmbr(Years))),@relative("YearTotal",0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");
	endif                
	                
elseif("OFS_Trend"->"BegBalance"==8)
			if(@isuda("Account","CalcRound"))
				"OFS_Calculated" = @Round(@prior("OEP_Forecast"->"OFS_Total Plan",1, @LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
			else
				"OFS_Calculated" = @prior("OEP_Forecast"->"OFS_Total Plan",1, @LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");
			endif
elseif("OFS_Trend"->"BegBalance"==10)
				if(@isuda("Account","calcRound"))
					"OFS_Calculated" = @Round(@prior("OFS_Total Plan",1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
				else
					"OFS_Calculated" = @prior("OFS_Total Plan",1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");
	endif]]></script></component><component id="7" name="Plan_Only_Weekly" product="Planning" type="script"><property name="application">HP4</property><property name="plantype">OEP_FS</property><property name="display_label">Plan_Only_Weekly</property><property name="seeded">true</property><script type="calcscript"><![CDATA[elseif("OFS_Trend"->"BegBalance"==6)
			if(@prior("TP-Weeks",1,@levmbrs(Years,0))==52)
				if(@isuda("Account","CalcRound"))
					"OFS_Calculated" = @Round(@avgrange(skipnone,"OEP_Forecast"->"OFS_Total Plan"->@member(@prevsibling(@currmbr(Years))),OEP_W1:OEP_W52)*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
				else
					"OFS_Calculated" = @avgrange(skipnone,"OEP_Forecast"->"OFS_Total Plan"->@member(@prevsibling(@currmbr(Years))),OEP_W1:OEP_W52)*(1+"OFS_% Increase/(Decrease)"->"BegBalance");
				endif        
			else
				if(@isuda("Account","CalcRound"))
					"OFS_Calculated" = @Round(@avgrange(skipnone,"OEP_Forecast"->"OFS_Total Plan"->@member(@prevsibling(@currmbr(Years))),@relative("OEP_Weekly Plan",0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
				else
					"OFS_Calculated" = @avgrange(skipnone,"OEP_Forecast"->"OFS_Total Plan"->@member(@prevsibling(@currmbr(Years))),@relative("OEP_Weekly Plan",0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");
				endif   
			 endif
elseif("OFS_Trend"->"BegBalance"==8)	
			if(@isuda("Account","CalcRound"))
				"OFS_Calculated" = @Round(@prior("OEP_Forecast"->"OFS_Total Plan",1, @LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
			else
				"OFS_Calculated" = @prior("OEP_Forecast"->"OFS_Total Plan",1, @LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");
			endif
elseif("OFS_Trend"->"BegBalance"==10)
			if(@isuda("Account","calcRound"))
				"OFS_Calculated" = @Round(@prior("OFS_Total Plan",1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
			else
				"OFS_Calculated" = @prior("OFS_Total Plan",1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");
			endif]]></script></component><component id="5" name="Qrtly_Trends" product="Planning" type="script"><property name="application">HP4</property><property name="plantype">OEP_FS</property><property name="display_label">Qrtly_Trends</property><property name="seeded">true</property><script type="calcscript"><![CDATA[If("OFS_Trend"->"BegBalance"==1)										
		if(@isuda("Account","CalcRound"))	
        	if(@isuda("Account","Flow"))
				"OFS_Calculated" = @Round((@AVGRANGE(SKIPNONE , "OEP_Actual"->"OFS_Load"->&OEP_CurYr , &OEP_StartMnth:&OEP_CurMnth))*"PeriodsInQtr"*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
            else
            	"OFS_Calculated" = @Round((@AVGRANGE(SKIPNONE , "OEP_Actual"->"OFS_Load"->&OEP_CurYr , &OEP_StartMnth:&OEP_CurMnth))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
            endif
		else
        	if(@isuda("Account","Flow"))
				OFS_Calculated =(@AVGRANGE(SKIPNONE , "OEP_Actual"->"OFS_Load"->&OEP_CurYr , &OEP_StartMnth:&OEP_CurMnth))*"PeriodsInQtr"*(1+"OFS_% Increase/(Decrease)"->"BegBalance");			
            else
            	OFS_Calculated =(@AVGRANGE(SKIPNONE , "OEP_Actual"->"OFS_Load"->&OEP_CurYr , &OEP_StartMnth:&OEP_CurMnth))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");		
            endif
		endif									
elseif("OFS_Trend"->"BegBalance"==2)										
		if(@isuda("Account","CalcRound"))
        	if(@isuda("Account","Flow"))
				OFS_Calculated =@Round((("OEP_Actual"->&OEP_CurMnth->&OEP_CurYr->"OFS_Load")*"PeriodsInQtr")*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));	
            else
            	OFS_Calculated =@Round((("OEP_Actual"->&OEP_CurMnth->&OEP_CurYr->"OFS_Load"))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));	
            endif
		else	
        	if(@isuda("Account","Flow"))
				OFS_Calculated = (("OEP_Actual"->&OEP_CurMnth->&OEP_CurYr->"OFS_Load")*"PeriodsInQtr")*(1+"OFS_% Increase/(Decrease)"->"BegBalance");	
            else
            	OFS_Calculated = (("OEP_Actual"->&OEP_CurMnth->&OEP_CurYr->"OFS_Load"))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");	
            endif
		endif									
	elseif("OFS_Trend"->"BegBalance"==4)										
		if(@isuda("Account","CalcRound"))		
        	if(@isuda("Account","Flow"))
				OFS_Calculated = @Round((@avgrange(skipnone,"OEP_Actual"->"OFS_Load"->&OEP_PriorYr,@relative("YearTotal",0))*"PeriodsInQtr")*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));		
            else
           		OFS_Calculated = @Round((@avgrange(skipnone,"OEP_Actual"->"OFS_Load"->&OEP_PriorYr,@relative("YearTotal",0)))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));	
            endif
		else	
        	if(@isuda("Account","Flow"))
				OFS_Calculated = (@avgrange(skipnone,"OEP_Actual"->"OFS_Load"->&OEP_PriorYr,@relative("YearTotal",0))*"PeriodsInQtr")*(1+"OFS_% Increase/(Decrease)"->"BegBalance");	
            else
            	OFS_Calculated = (@avgrange(skipnone,"OEP_Actual"->"OFS_Load"->&OEP_PriorYr,@relative("YearTotal",0)))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");
            endif
		endif												
	elseif("OFS_Trend"->"BegBalance"==10)										
		if(@prior("OEP_Qrtly Plan",1,@levmbrs("Years",0))<>#Missing)									
			if(@isuda("Account","CalcRound"))								
				@Round(@Prior("OFS_Total Plan",1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));							
			else								
				@Prior("OFS_Total Plan",1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");							
			endif								
		else									
			if(@isuda("Account","CalcRound"))								
				if(@ismbr("Qtrly 1"))							
					@Round(@Prior("OFS_Total Plan"->"Q1",1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));						
				elseif(@ismbr("Qtrly 2"))							
					@Round(@Prior("OFS_Total Plan"->"Q2",1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));						
				elseif(@ismbr("Qtrly 3"))							
					@Round(@Prior("OFS_Total Plan"->"Q3",1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));						
				elseif(@ismbr("Qtrly 4"))							
					@Round(@Prior("OFS_Total Plan"->"Q4",1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));						
				endif							
			else								
				if(@ismbr("Qtrly 1"))							
					@Prior("OFS_Total Plan"->"Q1",1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");						
				elseif(@ismbr("Qtrly 2"))							
					@Prior("OFS_Total Plan"->"Q2",1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");						
				elseif(@ismbr("Qtrly 3"))							
					@Prior("OFS_Total Plan"->"Q3",1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");						
				elseif(@ismbr("Qtrly 4"))							
					@Prior("OFS_Total Plan"->"Q4",1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");						
				endif							
			endif								
											
		endif									
	elseif("OFS_Trend"->BegBalance==12)										
				OFS_Calculated=#missing;							
	elseif("OFS_Trend"->BegBalance==#missing and "OFS_Adjustment (+/-)"<>#missing)																
				OFS_Calculated=0;
                OFS_Calculated=#missing;							
	endif										

]]></script></component><component id="2" name="Weekly_ForecastOnly" product="Planning" type="script"><property name="application">HP4</property><property name="plantype">OEP_FS</property><property name="display_label">Weekly_ForecastOnly</property><property name="seeded">true</property><script type="calcscript"><![CDATA[elseif("OFS_Trend"->"BegBalance"==3)						
	if(("OEP_Plan"->"OFS_Total Plan"->"OEP_Weekly Plan")-@sumrange("OEP_Actual"->"OFS_Load",OEP_W1:&OEP_CurWeek)>0)							
          if(@ISACCTYPE(LAST))				
              if(@isuda("Account","Calcround"))			
                  "OFS_Calculated"=@round("OEP_Plan"->"OFS_Total Plan");		
              else			
                  "OFS_Calculated" ="OEP_Plan"->"OFS_Total Plan";		
              endif			
          else				
              	if(@isuda("Account","Calcround"))		
				"OFS_Calculated"=@round((("OEP_Plan"->"OFS_Total Plan"->"OEP_Weekly Plan")-@sumrange("OEP_Actual"->"OFS_Load",OEP_W1:&OEP_CurWeek))/("TP-Weeks"-@count(skipnone,@range("OFS_Load",OEP_W1:&OEP_CurWeek))));				
                  else
				"OFS_Calculated"=((("OEP_Plan"->"OFS_Total Plan"->"OEP_Weekly Plan")-@sumrange("OEP_Actual"->"OFS_Load",OEP_W1:&OEP_CurWeek))/("TP-Weeks"-@count(skipnone,@range("OFS_Direct Input",OEP_W1:&OEP_CurWeek))));				
              endif			
          endif				
      else					
          "OFS_Calculated"=#missing;				
      endif	
elseif("OFS_Trend"->"BegBalance"==35)			
  	if(@isuda("Account","calcRound"))		  			
  		if(@ismbr(&OEP_FcstMnth))	
			"OFS_Calculated"=@round((@prior("OFS_Load"->OEP_Actual->&OEP_CurYr)*(@prior("OFS_Load"->OEP_Actual,1,@LEVMBRS ("Years", 0))+@prior("OFS_Load"->OEP_Actual,2,@LEVMBRS ("Years", 0)))/					
			(@MDSHIFT( "OFS_Load"->OEP_Actual, -1, "Period",@relative("OEP_Weekly Plan",0) , -1, "Years", )+@MDSHIFT( "OFS_Load"->OEP_Actual, -1, "Period",@relative("OEP_Weekly Plan",0) , -2, "Years", )))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));					
  		else
			"OFS_Calculated" =@round((@prior("OFS_Calculated")*					
  			(@prior("OFS_Load"->OEP_Actual,1,@LEVMBRS ("Years", 0))+@prior("OFS_Load"->OEP_Actual,2,@LEVMBRS ("Years", 0)))/
			(@MDSHIFT( "OFS_Load"->OEP_Actual, -1, "Period",@relative("OEP_Weekly Plan",0) , -1, "Years", )+@MDSHIFT( "OFS_Load"->OEP_Actual, -1, "Period",@relative("OEP_Weekly Plan",0) , -2, "Years", )))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));					
  		endif	
  	else		
  		if(@ismbr(&OEP_FcstMnth))	
			"OFS_Calculated"=((@prior("OFS_Load"->OEP_Actual->&OEP_CurYr)*(@prior("OFS_Load"->OEP_Actual,1,@LEVMBRS ("Years", 0))+@prior("OFS_Load"->OEP_Actual,2,@LEVMBRS ("Years", 0)))/					
			(@MDSHIFT( "OFS_Load"->OEP_Actual, -1, "Period",@relative("OEP_Weekly Plan",0) , -1, "Years", )+@MDSHIFT( "OFS_Load"->OEP_Actual, -1, "Period",@relative("OEP_Weekly Plan",0) , -2, "Years", )))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));					
  	 	else	 			
			"OFS_Calculated" =((@prior("OFS_Calculated")*					
  			(@prior("OFS_Load"->OEP_Actual,1,@LEVMBRS ("Years", 0))+@prior("OFS_Load"->OEP_Actual,2,@LEVMBRS ("Years", 0)))/
			(@MDSHIFT( "OFS_Load"->OEP_Actual, -1, "Period",@relative("OEP_Weekly Plan",0) , -1, "Years", )+@MDSHIFT( "OFS_Load"->OEP_Actual, -1, "Period",@relative("OEP_Weekly Plan",0) , -2, "Years", )))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));  					
  		endif	
  	endif	
elseif("OFS_Trend"->"BegBalance"==36)			
	if(@isuda("Account","calcRound"))					
		if(Not(@ismbr(OEP_W1:&OEP_CurWeek) and @ismbr(&OEP_CurYr)))	
			"OFS_Calculated"=@round((@prior("OFS_Load"->OEP_Actual->&OEP_CurYr))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));			
		elseif(@ismbr(OEP_W1) and @ismbr(@RSIBLINGS(&OEP_CurYr)))
       		"OFS_Calculated"=@round((@Prior("OFS_Total Plan"->OEP_W52,1,@LEVMBRS ("Years", 0)))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));
        else			
			"OFS_Calculated" =@round((@prior("OFS_Calculated")+@prior("OFS_Adjustment (+/-)"))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));			
		endif	
	else		
		if(Not(@ismbr(OEP_W1:&OEP_CurWeek) and @ismbr(&OEP_CurYr)))	
			"OFS_Calculated"=@prior("OFS_Load"->OEP_Actual->&OEP_CurYr)*(1+"OFS_% Increase/(Decrease)"->"BegBalance");			
		elseif(@ismbr(OEP_W1) and @ismbr(@RSIBLINGS(&OEP_CurYr)))
        	"OFS_Calculated"=@Prior("OFS_Total Plan"->OEP_W52,1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");
        else
			"OFS_Calculated" =(@prior("OFS_Calculated")+@prior("OFS_Adjustment (+/-)"))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");			
		endif	
	endif           ]]></script></component><component id="1" name="Weekly_Trends" product="Planning" type="script"><property name="application">HP4</property><property name="plantype">OEP_FS</property><property name="display_label">Weekly_Trends</property><property name="seeded">true</property><script type="calcscript"><![CDATA[If("OFS_Trend"->"BegBalance"==1)						
	if(@isuda("Account","CalcRound"))					
		"OFS_Calculated"=@Round(@AVGRANGE(SKIPNONE , "OEP_Actual"->"OFS_Load"->&OEP_CurYr , OEP_W1:&OEP_CurWeek)*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));				
	else					
		"OFS_Calculated"=@AVGRANGE(SKIPNONE , "OEP_Actual"->"OFS_Load"->&OEP_CurYr , OEP_W1:&OEP_CurWeek)*(1+"OFS_% Increase/(Decrease)"->"BegBalance");				
	endif					
elseif("OFS_Trend"->"BegBalance"==2)						
	if(@isuda("Account","CalcRound"))					
		"OFS_Calculated"=@Round(("OEP_Actual"->&OEP_CurWeek->&OEP_CurYr->"OFS_Load")*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));				
	else					
		"OFS_Calculated"=("OEP_Actual"->&OEP_CurWeek->&OEP_CurYr->"OFS_Load")*(1+"OFS_% Increase/(Decrease)"->"BegBalance");				
	endif					
elseif("OFS_Trend"->"BegBalance"==4)
	if("TP-Weeks"->&OEP_PriorYr==52)        
		if(@isuda("Account","CalcRound"))	 		  
			"OFS_Calculated"= @Round(@avgrange(skipnone,"OEP_Actual"->"OFS_Load"->&OEP_PriorYr,OEP_W1:OEP_W52)*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));				
		else					
			"OFS_Calculated"= @avgrange(skipnone,"OEP_Actual"->"OFS_Load"->&OEP_PriorYr,OEP_W1:OEP_W52)*(1+"OFS_% Increase/(Decrease)"->"BegBalance");				
		endif
	else       
		if(@isuda("Account","CalcRound"))	 		  
			"OFS_Calculated"= @Round(@avgrange(skipnone,"OEP_Actual"->"OFS_Load"->&OEP_PriorYr,@relative("OEP_Weekly Plan",0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));				
		else					
			"OFS_Calculated"= @avgrange(skipnone,"OEP_Actual"->"OFS_Load"->&OEP_PriorYr,@relative("OEP_Weekly Plan",0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");				
		endif
	endif
elseif("OFS_Trend"->"BegBalance"==5)						
	if(@isuda("Account","CalcRound"))					
		"OFS_Calculated"= @Round(("OEP_Actual"->"OFS_Load"->&OEP_PriorYr)*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));				
	else					
		"OFS_Calculated"= ("OEP_Actual"->"OFS_Load"->&OEP_PriorYr)*(1+"OFS_% Increase/(Decrease)"->"BegBalance");				
	endif					
elseif("OFS_Trend"->BegBalance==12)						
	"OFS_Calculated"=#missing;					
elseif("OFS_Trend"->BegBalance==#missing and "OFS_Adjustment (+/-)"<>#missing)										
	OFS_Calculated=0;
    OFS_Calculated=#missing;					]]></script></component><component id="6" name="Yearly_Trends" product="Planning" type="script"><property name="application">HP4</property><property name="plantype">OEP_FS</property><property name="display_label">Yearly_Trends</property><property name="seeded">true</property><script type="calcscript"><![CDATA[if("OFS_Trend"->"BegBalance"==10)							
	if(@prior("OEP_Yearly Plan"->"OFS_Total Plan",1,@levmbrs("Years",0))<>#Missing)						
		if(@isuda("Account","CalcRound"))					
			OFS_Calculated=@Round(@Prior("OFS_Total Plan",1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));				
		else					
			OFS_Calculated=@Prior("OFS_Total Plan",1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");				
		endif					
	elseif(@prior("OEP_Qrtly Plan"->"OFS_Total Plan",1,@levmbrs("Years",0))<>#Missing)						
		if(@isuda("Account","CalcRound"))					
			OFS_Calculated=@Round(@Prior("OFS_Total Plan"->"Qrtly Plan",1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));				
		else					
			OFS_Calculated=@Prior("OFS_Total Plan"->"Qrtly Plan",1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");				
		endif					
	elseif(@prior("YearTotal"->"OFS_Total Plan",1,@levmbrs("Years",0))<>#Missing)						
		if(@isuda("Account","CalcRound"))					
			OFS_Calculated=@Round(@Prior("OFS_Total Plan"->"YearTotal",1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance"));				
		else					
			OFS_Calculated=@Prior("OFS_Total Plan"->"YearTotal",1,@LEVMBRS ("Years", 0))*(1+"OFS_% Increase/(Decrease)"->"BegBalance");				
		endif					
	endif						
							
elseif("OFS_Trend"->BegBalance==12)							
			OFS_Calculated=#missing;				
elseif("OFS_Trend"->BegBalance==#missing and "OFS_Adjustment (+/-)"<>#missing)	
			OFS_Calculated=0;
			OFS_Calculated=#missing;				
endif							


]]></script></component></components><deployobjects><deployobject application="hp4" name="OFS_GRIDMEMBERSELECTION_GT" obj_id="1" obj_type="19" plantype="oep_fs" product="2"/><deployobject application="hp4" name="OFS_TREND BASED CALCULATION" obj_id="1" obj_type="1" plantype="oep_fs" product="2"/></deployobjects><templates><template custom="yes" id="1" name="OFS_GridMemberSelection_GT" product="Planning"><property name="description">This groovy template is used in out of box rules and templates. So any customization to this groovy template may cause regressions.</property><property name="application">HP4</property><property name="plantype">OEP_FS</property><property name="formBusinessRule">false</property><property name="formCallback">false</property><property name="formContextMenu">false</property><property name="protected">false</property><property name="seeded">true</property><property name="standAlone">false</property><property name="systemCallback">false</property><script type="groovy"><![CDATA[class GridMemberSelection {
	DataGrid grid
	Map<String, String> povDimNameToMemberNameMap
	List<Map<String, String>> rowsDimNameToMemberNameMapList
	Map<String, Set<String>> columnsDimNameToMembersMap = [:]
	GridMemberSelection(DataGrid grid) {
		this.grid = grid
		Closure<Map<String, String>> dimNameToMemberSelectionMap = { List<DataGrid.HeaderCell> headerCells ->
			headerCells?.collectEntries { [ (it.dimName) : it.mbrName ] }
		}
		this.povDimNameToMemberNameMap = dimNameToMemberSelectionMap(grid.pov)
		this.rowsDimNameToMemberNameMapList = grid.rows.collect {dimNameToMemberSelectionMap(it.headers)}
		grid.columns.each {List<DataGrid.HeaderCell> it -> columnsDimNameToMembersMap.put(it.get(0).dimName, it*.mbrName as LinkedHashSet)}
	}

	String getPovSelection(String dimName) {
		povDimNameToMemberNameMap?.get(dimName)
	}

	List<String> getColumnSelection(String dimName) {
		Set<String> columnSelectionSet = columnsDimNameToMembersMap?.get(dimName)
		columnSelectionSet ? new ArrayList<String>(columnSelectionSet) : null
	}

	List<String> getRowSelection(String dimName) {
		List<String> rowSelectionListWithDuplicates = rowsDimNameToMemberNameMapList*.get(dimName)
		rowSelectionListWithDuplicates ? new ArrayList<String>(rowSelectionListWithDuplicates as LinkedHashSet) : null
	}

	List<String> getMemberSelection(String dimName) throws Exception{
		String povSelection = getPovSelection(dimName)
		List<String> memberSelection = povSelection ? [povSelection] : (getColumnSelection(dimName)?:getRowSelection(dimName))
		if(memberSelection) {
			return memberSelection
		} else {
			throw new Exception("Dimension: " + dimName + " isn't present in the grid.")
		}
	}

	String getMemberFromSelection(String dimName) throws Exception {
		List<String> memberSelection = getMemberSelection(dimName)
		if(memberSelection.size() > 1) {
			throw new Exception("Dimension: " + dimName + " has multiple members in the selection but you can have only a single member.")
		}
		memberSelection.get(0)
	}

	List<String> getMemberSelectionWithLeafMembers(Cube financialsCube, Application application, String dimName) throws Exception{
		List<String> memberelection = getMemberSelection(dimName)
		Dimension dimension = application.getDimension(dimName, financialsCube)
		if(!dimension) {
			//FIXME:Not able to throw Veto exception
			throw new Exception("Dimension: " + dimName + " isn't present in the grid.")
		}
		//FIXME:Beter way to get Levl0 members
		return memberelection?.findAll { !dimension.getEvaluatedMembers("Descendants("+it+")", financialsCube) }
	}
}

	]]></script><template_wizard/><template_prompts><restricted_prompt isPrompt="no" name="Application Type" type="Application Type"><property name="is_system">true</property><restricted_prompt_item><property name="prompt">Is Generic</property><property name="value">GENERAL</property></restricted_prompt_item><restricted_prompt_item><property name="prompt">Is PFP</property><property name="value">PROJECT</property></restricted_prompt_item><restricted_prompt_item><property name="prompt">Is PSB</property><property name="value">PSB</property></restricted_prompt_item></restricted_prompt><restricted_prompt isPrompt="no" name="Application" type="Application"><property name="is_system">true</property><value>Is Single Currency</value><restricted_prompt_item><property name="prompt">Is Multi Currency</property><property name="value">multi</property></restricted_prompt_item><restricted_prompt_item><property name="prompt">Is Single Currency</property><property name="value">single</property></restricted_prompt_item><restricted_prompt_item><property name="prompt">Is Simple Currency</property><property name="value">simple</property></restricted_prompt_item></restricted_prompt><template_slice_prompt isPrompt="false" name="UpperPOV" type="Member Range"><property name="is_system">true</property></template_slice_prompt><restricted_prompt isPrompt="no" name="Essbase Mode" type="Essbase Mode"><property name="is_system">true</property><restricted_prompt_item><property name="prompt">Is Hybrid</property><property name="value">Hybrid</property></restricted_prompt_item><restricted_prompt_item><property name="prompt">Is NonHybrid</property><property name="value">NonHybrid</property></restricted_prompt_item></restricted_prompt></template_prompts></template></templates></HBRRepo>